package com.creditease.rss.ui.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.creditease.rss.model.RssItemModel;
import com.creditease.rss.ui.R;

public class RssItemAdapter extends BaseAdapter {

	private static final String TAG = RssItemAdapter.class.getSimpleName();

	private Context context;

	private List<RssItemModel> list;

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public RssItemAdapter(Context context, List<RssItemModel> list) {
		super();
		this.context = context;
		this.list = list;
	}

	private SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		convertView = LayoutInflater.from(context).inflate(R.layout.rss_item, null);
		RssItemModel itemModel = list.get(position);
		TextView mTextView = (TextView) convertView.findViewById(R.id.title);
		TextView timeView = (TextView) convertView.findViewById(R.id.time);
		ImageView logo = (ImageView) convertView.findViewById(R.id.list_item_pic);

		mTextView.setText(itemModel.articleTitle);
		timeView.setText(sdfDateFormat.format(new Date(itemModel.articleTime)));
		// 已读
		if (itemModel.isRead) {
			//Log.d(TAG, itemModel.isRead + " ====");
			mTextView.setTextColor(R.color.solid_black);
			timeView.setTextColor(R.color.bg_gray);
			logo.setImageResource(R.drawable.rss_list_offline);
		} else {
			//Log.d(TAG, itemModel.isRead + "---");
			mTextView.setTextColor(Color.BLACK);
			timeView.setTextColor(Color.RED);
			logo.setImageResource(R.drawable.rss_list_online);
		}

		return convertView;
	}

}
